<!doctype html>
<html lang="en">
<head>
    <title>Code coverage report for components/ThemePicker/index.vue</title>
    <meta charset="utf-8" />
    <link rel="stylesheet" href="../../prettify.css" />
    <link rel="stylesheet" href="../../base.css" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style type='text/css'>
        .coverage-summary .sorter {
            background-image: url(../../sort-arrow-sprite.png);
        }
    </style>
</head>
<body>
<div class='wrapper'>
  <div class='pad1'>
    <h1>
      <a href="../../index.html">All files</a> / <a href="index.html">components/ThemePicker</a> index.vue
    </h1>
    <div class='clearfix'>
      <div class='fl pad1y space-right2'>
        <span class="strong">0% </span>
        <span class="quiet">Statements</span>
        <span class='fraction'>0/77</span>
      </div>
      <div class='fl pad1y space-right2'>
        <span class="strong">0% </span>
        <span class="quiet">Branches</span>
        <span class='fraction'>0/18</span>
      </div>
      <div class='fl pad1y space-right2'>
        <span class="strong">0% </span>
        <span class="quiet">Functions</span>
        <span class='fraction'>0/16</span>
      </div>
      <div class='fl pad1y space-right2'>
        <span class="strong">0% </span>
        <span class="quiet">Lines</span>
        <span class='fraction'>0/76</span>
      </div>
    </div>
  </div>
  <div class='status-line low'></div>
<pre><table class="coverage">
<tr><td class="line-count quiet">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158</td><td class="line-coverage quiet"><span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span></td><td class="text"><pre class="prettyprint lang-js">&lt;template&gt;
  &lt;el-color-picker
    v-model="theme"
    :predefine="['#409EFF', '#1890ff', '#304156','#212121','#11a983', '#13c2c2', '#6959CD', '#f5222d']"
    class="theme-picker"
    popper-class="theme-picker-dropdown"
  /&gt;
&lt;/template&gt;
&nbsp;
&lt;script lang="ts"&gt;
<span class="cstat-no" title="statement not covered" >import { Component, Prop, Vue, Watch } from 'vue-property-decorator'</span>
<span class="cstat-no" title="statement not covered" >import { SettingsModule } from '@/store/modules/settings'</span>
&nbsp;
<span class="cstat-no" title="statement not covered" >const version = require('element-ui/package.json').version // element-ui version from node_modules</span>
<span class="cstat-no" title="statement not covered" >const ORIGINAL_THEME = '#409EFF' // default color</span>
&nbsp;
<span class="fstat-no" title="function not covered" >@Component({</span>
  name: 'ThemePicker'
})
<span class="cstat-no" title="statement not covered" ><span class="cstat-no" title="statement not covered" >export default class extends Vue {</span></span>
<span class="cstat-no" title="statement not covered" >  private chalk = '' // The content of theme-chalk css</span>
<span class="cstat-no" title="statement not covered" >  private theme = ''</span>
&nbsp;
<span class="fstat-no" title="function not covered" >  get defaultTheme() {</span>
<span class="cstat-no" title="statement not covered" >    return SettingsModule.theme</span>
  }
&nbsp;
  @Watch('defaultTheme', { immediate: true })
<span class="cstat-no" title="statement not covered" ><span class="fstat-no" title="function not covered" >  private onDefaultThemeChange(value: string) {</span></span>
<span class="cstat-no" title="statement not covered" >    this.theme = value</span>
  }
&nbsp;
  @Watch('theme')
<span class="cstat-no" title="statement not covered" ><span class="fstat-no" title="function not covered" >  private async onThemeChange(value: string) {</span></span>
<span class="cstat-no" title="statement not covered" >    if (!value) return</span>
<span class="cstat-no" title="statement not covered" >    const oldValue = this.chalk ? this.theme : ORIGINAL_THEME</span>
<span class="cstat-no" title="statement not covered" >    const themeCluster = this.getThemeCluster(value.replace('#', ''))</span>
<span class="cstat-no" title="statement not covered" >    const originalCluster = this.getThemeCluster(oldValue.replace('#', ''))</span>
<span class="cstat-no" title="statement not covered" >    const message = this.$message({</span>
      message: '  Compiling the theme',
      customClass: 'theme-message',
      type: 'success',
      duration: 0,
      iconClass: 'el-icon-loading'
    })
&nbsp;
<span class="cstat-no" title="statement not covered" >    if (!this.chalk) {</span>
<span class="cstat-no" title="statement not covered" >      const url = `https://unpkg.com/element-ui@${version}/lib/theme-chalk/index.css`</span>
<span class="cstat-no" title="statement not covered" >      await this.getCSSString(url, 'chalk')</span>
    }
&nbsp;
<span class="cstat-no" title="statement not covered" ><span class="fstat-no" title="function not covered" >    const getHandler = (variable: string, id: string) =&gt; {</span></span>
<span class="cstat-no" title="statement not covered" ><span class="fstat-no" title="function not covered" >      return () =&gt; {</span></span>
<span class="cstat-no" title="statement not covered" >        const originalCluster = this.getThemeCluster(ORIGINAL_THEME.replace('#', ''))</span>
<span class="cstat-no" title="statement not covered" >        const newStyle = this.updateStyle((this as any)[variable], originalCluster, themeCluster)</span>
&nbsp;
<span class="cstat-no" title="statement not covered" >        let styleTag = document.getElementById(id)</span>
<span class="cstat-no" title="statement not covered" >        if (!styleTag) {</span>
<span class="cstat-no" title="statement not covered" >          styleTag = document.createElement('style')</span>
<span class="cstat-no" title="statement not covered" >          styleTag.setAttribute('id', id)</span>
<span class="cstat-no" title="statement not covered" >          document.head.appendChild(styleTag)</span>
        }
<span class="cstat-no" title="statement not covered" >        styleTag.innerText = newStyle</span>
      }
    }
<span class="cstat-no" title="statement not covered" >    const chalkHandler = getHandler('chalk', 'chalk-style')</span>
<span class="cstat-no" title="statement not covered" >    chalkHandler()</span>
&nbsp;
<span class="cstat-no" title="statement not covered" >    let styles: HTMLElement[] = [].slice.call(document.querySelectorAll('style'))</span>
<span class="cstat-no" title="statement not covered" ><span class="fstat-no" title="function not covered" >    styles = styles</span></span>
      .filter(style =&gt; {
<span class="cstat-no" title="statement not covered" >        const text = style.innerText</span>
<span class="cstat-no" title="statement not covered" >        return new RegExp(oldValue, 'i').test(text) &amp;&amp; !/Chalk Variables/.test(text)</span>
      })
<span class="cstat-no" title="statement not covered" ><span class="fstat-no" title="function not covered" >    styles.forEach(style =&gt; {</span></span>
<span class="cstat-no" title="statement not covered" >      const { innerText } = style</span>
<span class="cstat-no" title="statement not covered" >      if (typeof innerText !== 'string') return</span>
<span class="cstat-no" title="statement not covered" >      style.innerText = this.updateStyle(innerText, originalCluster, themeCluster)</span>
    })
&nbsp;
<span class="cstat-no" title="statement not covered" >    this.$emit('change', value)</span>
<span class="cstat-no" title="statement not covered" >    message.close()</span>
  }
&nbsp;
<span class="fstat-no" title="function not covered" >  private updateStyle(style: string, oldCluster: string[], newCluster: string[]) {</span>
<span class="cstat-no" title="statement not covered" >    let newStyle = style</span>
<span class="cstat-no" title="statement not covered" ><span class="fstat-no" title="function not covered" >    oldCluster.forEach((color, index) =&gt; {</span></span>
<span class="cstat-no" title="statement not covered" >      newStyle = newStyle.replace(new RegExp(color, 'ig'), newCluster[index])</span>
    })
<span class="cstat-no" title="statement not covered" >    return newStyle</span>
  }
&nbsp;
<span class="fstat-no" title="function not covered" >  private getCSSString(url: string, variable: string) {</span>
<span class="cstat-no" title="statement not covered" ><span class="fstat-no" title="function not covered" >    return new Promise(resolve =&gt; {</span></span>
<span class="cstat-no" title="statement not covered" >      const xhr = new XMLHttpRequest()</span>
<span class="cstat-no" title="statement not covered" ><span class="fstat-no" title="function not covered" >      xhr.onreadystatechange = () =&gt; {</span></span>
<span class="cstat-no" title="statement not covered" >        if (xhr.readyState === 4 &amp;&amp; xhr.status === 200) {</span>
<span class="cstat-no" title="statement not covered" >          (this as any)[variable] = xhr.responseText.replace(/@font-face{[^}]+}/, '')</span>
<span class="cstat-no" title="statement not covered" >          resolve()</span>
        }
      }
<span class="cstat-no" title="statement not covered" >      xhr.open('GET', url)</span>
<span class="cstat-no" title="statement not covered" >      xhr.send()</span>
    })
  }
&nbsp;
<span class="fstat-no" title="function not covered" >  private getThemeCluster(theme: string) {</span>
<span class="cstat-no" title="statement not covered" ><span class="fstat-no" title="function not covered" >    const tintColor = (color: string, tint: number) =&gt; {</span></span>
<span class="cstat-no" title="statement not covered" >      let red = parseInt(color.slice(0, 2), 16)</span>
<span class="cstat-no" title="statement not covered" >      let green = parseInt(color.slice(2, 4), 16)</span>
<span class="cstat-no" title="statement not covered" >      let blue = parseInt(color.slice(4, 6), 16)</span>
<span class="cstat-no" title="statement not covered" >      if (tint === 0) { // when primary color is in its rgb space</span>
<span class="cstat-no" title="statement not covered" >        return [red, green, blue].join(',')</span>
      } else {
<span class="cstat-no" title="statement not covered" >        red += Math.round(tint * (255 - red))</span>
<span class="cstat-no" title="statement not covered" >        green += Math.round(tint * (255 - green))</span>
<span class="cstat-no" title="statement not covered" >        blue += Math.round(tint * (255 - blue))</span>
<span class="cstat-no" title="statement not covered" >        return `#${red.toString(16)}${green.toString(16)}${blue.toString(16)}`</span>
      }
    }
&nbsp;
<span class="cstat-no" title="statement not covered" ><span class="fstat-no" title="function not covered" >    const shadeColor = (color: string, shade: number) =&gt; {</span></span>
<span class="cstat-no" title="statement not covered" >      let red = parseInt(color.slice(0, 2), 16)</span>
<span class="cstat-no" title="statement not covered" >      let green = parseInt(color.slice(2, 4), 16)</span>
<span class="cstat-no" title="statement not covered" >      let blue = parseInt(color.slice(4, 6), 16)</span>
<span class="cstat-no" title="statement not covered" >      red = Math.round((1 - shade) * red)</span>
<span class="cstat-no" title="statement not covered" >      green = Math.round((1 - shade) * green)</span>
<span class="cstat-no" title="statement not covered" >      blue = Math.round((1 - shade) * blue)</span>
<span class="cstat-no" title="statement not covered" >      return `#${red.toString(16)}${green.toString(16)}${blue.toString(16)}`</span>
    }
&nbsp;
<span class="cstat-no" title="statement not covered" >    const clusters = [theme]</span>
<span class="cstat-no" title="statement not covered" >    for (let i = 0; i &lt;= 9; i++) {</span>
<span class="cstat-no" title="statement not covered" >      clusters.push(tintColor(theme, Number((i / 10).toFixed(2))))</span>
    }
<span class="cstat-no" title="statement not covered" >    clusters.push(shadeColor(theme, 0.1))</span>
<span class="cstat-no" title="statement not covered" >    return clusters</span>
  }
}
&lt;/script&gt;
&nbsp;
&lt;style lang="scss"&gt;
.theme-message,
.theme-picker-dropdown {
  z-index: 99999 !important;
}
&nbsp;
.theme-picker .el-color-picker__trigger {
  height: 26px !important;
  width: 26px !important;
  padding: 2px;
}
&nbsp;
.theme-picker-dropdown .el-color-dropdown__link-btn {
  display: none;
}
&lt;/style&gt;
&nbsp;</pre></td></tr>
</table></pre>
<div class='push'></div><!-- for sticky footer -->
</div><!-- /wrapper -->
<div class='footer quiet pad2 space-top1 center small'>
  Code coverage
  generated by <a href="https://istanbul.js.org/" target="_blank">istanbul</a> at Mon Aug 05 2019 17:01:25 GMT+0800 (GMT+08:00)
</div>
</div>
<script src="../../prettify.js"></script>
<script>
window.onload = function () {
        if (typeof prettyPrint === 'function') {
            prettyPrint();
        }
};
</script>
<script src="../../sorter.js"></script>
</body>
</html>
